/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


var error_count=0;
var cek_nama = /^[A-Za-z0-9 ]{5,50}$/;
var ck_email = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;

function cek_teamname(){
     if (!cek_nama.test(document.regform.team_name.value)){
        document.getElementById("invalid_teamname").innerHTML="invalid team name";
        return false;
    }
    else{
        document.getElementById("invalid_teamname").innerHTML="";
        return true;
    }
}

function cek_membername_1(){
    if (!cek_nama.test(document.regform.member_name_1.value)){
        document.getElementById("invalid_membername1").innerHTML="invalid member name";
        return false;
    }
    else{
        document.getElementById("invalid_membername1").innerHTML="";
        return true;
    }
}

function cek_membername_2(){
    if (!cek_nama.test(document.regform.member_name_2.value)){
        document.getElementById("invalid_membername2").innerHTML="invalid member name";
        return false;
    }
    else{
        document.getElementById("invalid_membername2").innerHTML="";
        return true;
    }
}

function cek_membername_3(){
    if (!cek_nama.test(document.regform.member_name_3.value)){
        document.getElementById("invalid_membername3").innerHTML="invalid member name";
        return false;
    }
    else{
        document.getElementById("invalid_membername3").innerHTML="";
        return true;
    }
}

function cek_membername_4(){
    if (!cek_nama.test(document.regform.member_name_4.value)){
        document.getElementById("invalid_membername4").innerHTML="invalid member name";
        return false;
    }
    else{
        document.getElementById("invalid_membername4").innerHTML="";
        return true;
    }
}

function cek_username(){
     if (!cek_nama.test(document.regform.username.value)){
        document.getElementById("invalid_username").innerHTML="invalid username";
        return false;
    }
    else{
        document.getElementById("invalid_username").innerHTML="";
        return true;
    }
    
}

function cek_password(){
    if (document.regform.password.value != document.regform.repassword.value){
       document.getElementById("password_mismatch").innerHTML="password did not match";
       return false;
    }
    else{
       document.getElementById("password_mismatch").innerHTML="";
       return true;
    }
}

function cek_email(){
    if(!ck_email.test(document.regform.email.value)){
        document.getElementById("invalid_email").innerHTML="invalid email";
        return false;
    }
    else{
        document.getElementById("invalid_email").innerHTML="";
        return true;
    }
}

function validate(){
    var a = cek_email();
    var b = cek_membername_1();
    var c = cek_membername_2();
    var d = cek_membername_3();
    var e = cek_membername_4();
    var f = cek_password();
    var g = cek_teamname();
    var h = cek_username();
    
    
    var hostname = window.location.hostname;
    if (a && b && c && d && e && f && g && h){
         return true;
    }
    else{
        return false;
//        alert('Form invalid. There is something wrong on your input');
//        
//        window.location="http://"+hostname+"/iecom/registration/form/";
    }
}